/**
 * 
 */
package org.mhz.ootw.tree;

import java.util.ArrayList;
import java.util.List;

import org.mhz.ootw.util.JSONHelper;

/**
 * @author Mahan
 *
 * 
 */
public class JsTreeNode
{
    private Attributes mAttributes;      
    private Data mData;         
    private String mState;             
    private List<JsTreeNode> mChildren;         
   
    /**
     * Default constructor
     */
    public JsTreeNode()
    {
        mChildren = new  ArrayList<JsTreeNode>();
        mData = new Data();
        mAttributes = new Attributes();
    }   
    
    /**
     * @param aTitle - The title
     * @param aState - The state
     */
    public JsTreeNode(final String aTitle, final String aState)
    {
        this();
        mData.setTitle(aTitle);
        mState = aState;
    }
    
    /**
     * @return Returns the attributes.
     */
    public Attributes getAttributes()
    {
        return mAttributes;
    }
    
    /**
     * @param aAttributes The attributes to set.
     */
    public void setAttributes(final Attributes aAttributes)
    {
        mAttributes = aAttributes;
    }
    
    /**
     * @return Returns the data.
     */
    public Data getData()
    {
        return mData;
    }
    
    /**
     * @param aData The data to set.
     */
    public void setData(final Data aData)
    {
        mData = aData;
    }
    
    /**
     * @return Returns the state.
     */
    public String getState()
    {
        return mState;
    }
    
    /**
     * @param aState The state to set.
     */
    public void setState(final String aState)
    {
        mState = aState;
    }
    
    /**
     * @return Returns the children.
     */
    public List<JsTreeNode> getChildren()
    {
        return mChildren;
    }
    
    /**
     * @param aChildren The children to set.
     */
    public void setChildren(final List<JsTreeNode> aChildren)
    {
        mChildren = aChildren;
    }

    /**
     * @return The object as a json string
     */
    public String jsonString()
    {
        return "{\"metadata\":" + mAttributes.jsonString() 
                + ", \"state\":\"" + mState
                + "\", \"data\":" + mData.jsonString()                
                + ", \"children\":" + JSONHelper.jsTreeNodesAsJSONString(mChildren) + "}";
    }

    /* (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString()
    {
        return "JsTreeNode [mAttributes=" + mAttributes + ", mData=" + mData
                + ", mState=" + mState + ", mChildren=" + mChildren + "]";
    }     
        
}
